const Compare = {
  LESS_THAN: -1,
  BIGGER_THAN: 1
};

const BalanceFactor = {
  UNBALANCED_RIGHT: 1,
  SLIGHTLY_UNBALANCED_RIGHT: 2,
  BALANCED: 3,
  SLIGHTLY_UNBALANCED_LEFT: 4,
  UNBALANCED_LEFT: 5
};

function defaultEquals(a, b) {
  // 判断 a 和 b 是否严格相等
  return a === b; // 这里是基础类型的判断 可以在这里自定义复杂类型的比较判断
}

function defaultCompare(a, b) {
  if (a === b) {
    return 0;
  }
  return a < b ? Compare.LESS_THAN : Compare.BIGGER_THAN;
}

function defaultToString(item) {
  if (item === null) {
    return 'NULL';
  }
  if (item === undefined) {
    return 'UNDEFINED';
  }
  if (typeof item === 'string' || item instanceof String) {
    return `${item}`;
  }
  return item.toString();
}

function swap(array, a, b) {
  /* const temp = array[a];
  array[a] = array[b];
  array[b] = temp; */
  [array[a], array[b]] = [array[b], array[a]];
}

exports.Compare = Compare;
exports.BalanceFactor = BalanceFactor;
exports.defaultEquals = defaultEquals;
exports.defaultCompare = defaultCompare;
exports.defaultToString = defaultToString;
exports.swap = swap;
